package com.example.actearly_revised;
import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class ButtonAdapter extends ArrayAdapter<Model> {

	private final List<Model> list;
	private final Activity context;
	
	public ButtonAdapter(Activity context, List<Model> list) {
		super(context, R.layout.activity_list_layout, list);
		this.context = context;
		this.list = list;
	}

	static class ViewHolder {
		protected TextView text;
		protected Button button;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.activity_list_layout, null);
			final ViewHolder viewHolder = new ViewHolder();
			//viewHolder.text = (TextView) view.findViewById(R.id.label);
			viewHolder.text.setTextColor(Color.BLACK);
			
			//viewHolder.button = (Button) view.findViewById(R.id.button);
			//viewHolder.button.setBackgroundColor(Color.GRAY);
			//this SHOULD be code to check when a button is clicked
			
/*			
			numClicks=0;
			viewHolder.button.setOnClickListener(new View.OnClickListener() {
				public void onClick(View view) {
					Model element = (Model) viewHolder.button.getTag();
				}
			});
			*/
			view.setTag(viewHolder);
			viewHolder.button.setTag(list.get(position));
		} else {
			view = convertView;
			((ViewHolder) view.getTag()).button.setTag(list.get(position));
		}
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.text.setText(list.get(position).getName());
		//holder.button.setChecked(list.get(position).isSelected());
		return view;
	}
}